//1
let isDone: boolean = false

let age: number = 10

let firstName: string = 'hugo'
let message: string = `Hello, ${firstName}`

let u: undefined = undefined
let n: null = null

let num: number = undefined

// any
let notSure: any = 4
notSure = 'maybe a string'
notSure = true

notSure.myName = 'hugo'
notSure.getName()

//2
let arrOfNumbers: number[] = [1,2,3]
arrOfNumbers.push(3)

// 类数组
function test(){
    console.log(arguments)
}

// 元组
let user: [string, number] = ['hugo', 13]
user.push('banana')
user.push(1314)

// 函数
const add = (x: number, y: number, z?: number): number=> { // z? 可选参数
    if (typeof z === 'number'){
        return x + y + x
    }else{
        return x + y
    }
}
let result = add(1, 3, 5)

let add2: (x: number, y: number, z?: number) => number = add

// 接口
interface ISum{
    (x: number, y: number, z?: number): number
}
let add3: ISum = add

// 类型推断
let str = 'str'


// 联合类型 union types
let numberOrString: number | string
numberOrString.toString()

function getLength(input: string | number): number{
    const str = input as string
    if(str.length){
        return str.length
    }else{
        const number = input as number
        return number.toString().length
    }
}

// type guard
function getLength2(input: string | number): number{
    if(typeof input === 'string'){
        return input.length
    }else{
        return input.toString().length
    }
}


// 类 Class

